﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using System.Collections;
using System.Collections.Generic;

#endregion

namespace InterLinq.Test {
	/// <summary>
	/// Factory for creation sample data
	/// </summary>
	public class SampleDataFactory {
		#region Public Methods

		/// <summary>
		/// returns dynamically generated orders
		/// </summary>
		/// <returns></returns>
		public static Dictionary<Type, IList> CreateOrdersWithContent() {
			var randomizer = new Random(DateTime.Now.Millisecond);
			int productsCount = randomizer.Next(10, 200);
			int orderCount = randomizer.Next(2, 30);

			var products = new List<IProduct>();
			for (int i = 0; i < productsCount; i++) {
				products.Add(new Product("Product: " + i, (decimal)((int)(randomizer.NextDouble() * 100) / 100.0) * 50));
			}

			var orders = new List<IOrder>();
			for (int i = 0; i < orderCount; i++) {
				var order = new Order();
				int orderPositionCount = randomizer.Next(0, 50);
				for (int y = 0; y < orderPositionCount; y++) {
					order.OrderPositions.Add(new OrderPosition(randomizer.Next(0, 100),
																 products[randomizer.Next(0, products.Count - 1)]));
				}
				orders.Add(order);
			}
			var toReturn = new Dictionary<Type, IList>();
			toReturn.Add(typeof(IOrder), orders);
			toReturn.Add(typeof(IProduct), products);
			return toReturn;
		}

		/// <summary>
		/// returns dynamically generated orders
		/// </summary>
		/// <returns></returns>
		internal static Dictionary<Type, IList> CreateWPFOrdersWithContent() {
			return CreateWPFOrdersWithContent(10, 100);
		}

		/// <summary>
		/// returns dynamically generated orders
		/// </summary>
		/// <returns></returns>
		internal static Dictionary<Type, IList> CreateWPFOrdersWithContent(int countProductsFrom, int countProductsTo) {
			var randomizer = new Random(DateTime.Now.Millisecond);
			int productsCount = randomizer.Next(countProductsFrom, countProductsTo);
			int orderCount = randomizer.Next(2, 30);

			var products = new List<IProduct>();
			for (int i = 0; i < productsCount; i++) {
				products.Add(new WPFProduct("Product: " + i, (decimal)((int)(randomizer.NextDouble() * 100) / 100.0) * 50));
			}

			var orders = new List<IOrder>();
			for (int i = 0; i < orderCount; i++) {
				var order = new WPFOrder();
				int orderPositionCount = randomizer.Next(0, 50);
				for (int y = 0; y < orderPositionCount; y++) {
					order.OrderPositions.Add(new WPFOrderPosition(randomizer.Next(0, 100),
																	products[randomizer.Next(0, products.Count - 1)]));
				}
				orders.Add(order);
			}
			var toReturn = new Dictionary<Type, IList>();
			toReturn.Add(typeof(IOrder), orders);
			toReturn.Add(typeof(IProduct), products);
			return toReturn;
		}

		public static Dictionary<Type, IList> CreateInterLinqOrdersWithContentSmall() {
			var products = new List<IProduct>();
			var orderPosition = new List<IOrderPosition>();
			for (int i = 0; i < 1; i++) {
				products.Add(new InterLinqProduct("Product: " + i, 20));
			}

			var orders = new List<IOrder>();
			for (int i = 0; i < 1; i++) {
				var order = new InterLinqOrder();
				int orderPositionCount = 1;
				for (int y = 0; y < orderPositionCount; y++) {
					var pos = new InterLinqOrderPosition(50, products[0]);
					order.OrderPositions.Add(pos);
					orderPosition.Add(pos);
				}
				orders.Add(order);
			}
			var toReturn = new Dictionary<Type, IList>();
			toReturn.Add(typeof(IOrder), orders);
			toReturn.Add(typeof(IProduct), products);
			toReturn.Add(typeof(IOrderPosition), orderPosition);
			return toReturn;
		}

		/// <summary>
		/// returns dynamically generated orders
		/// </summary>
		/// <returns></returns>
		public static Dictionary<Type, IList> CreateInterLinqOrdersWithContent(int countProductsFrom, int countProductsTo) {
			var randomizer = new Random(DateTime.Now.Millisecond);
			int productsCount = randomizer.Next(countProductsFrom, countProductsTo);
			int orderCount = randomizer.Next(2, 30);

			var products = new List<IProduct>();
			var orderPosition = new List<IOrderPosition>();
			for (int i = 0; i < productsCount; i++) {
				products.Add(new InterLinqProduct("Product: " + i, (decimal)((int)(randomizer.NextDouble() * 100) / 100.0) * 50));
			}

			var orders = new List<IOrder>();
			for (int i = 0; i < orderCount; i++) {
				var order = new InterLinqOrder();
				order.Name = "Order: " + i;
				int orderPositionCount = randomizer.Next(0, 50);
				for (int y = 0; y < orderPositionCount; y++) {
					var pos = new InterLinqOrderPosition(randomizer.Next(0, 100), products[randomizer.Next(0, products.Count - 1)]);
					order.OrderPositions.Add(pos);
					orderPosition.Add(pos);
				}
				orders.Add(order);
			}
			var toReturn = new Dictionary<Type, IList>();
			toReturn.Add(typeof(IOrder), orders);
			toReturn.Add(typeof(IProduct), products);
			toReturn.Add(typeof(IOrderPosition), orderPosition);
			return toReturn;
		}

		public static Dictionary<Type, IList> CreateLinqToSQLOrdersWithContent() {
			return CreateLinqToSQLOrdersWithContent(10, 200);
		}

		/// returns dynamically generated orders
		/// </summary>
		/// <returns></returns>
		public static Dictionary<Type, IList> CreateLinqToSQLOrdersWithContent(int countProductsFrom, int countProductsTo) {
			var randomizer = new Random(DateTime.Now.Millisecond);
			int productsCount = randomizer.Next(countProductsFrom, countProductsTo);
			int orderCount = randomizer.Next(2, 30);

			var products = new List<IProduct>();
			for (int i = 0; i < productsCount; i++) {
				products.Add(new DH.SQL.Product {
					Id = Guid.NewGuid(),
					Name = "Product: " + i,
					Price = (decimal)((int)(randomizer.NextDouble() * 100) / 100.0) * 50
				});
			}

			var orders = new List<IOrder>();
			for (int i = 0; i < orderCount; i++) {
				var order = new DH.SQL.Order { Name = "Order:" + i, Id = Guid.NewGuid() };
				int orderPositionCount = randomizer.Next(2, 50);
				for (int y = 0; y < orderPositionCount; y++) {
					order.AddOrderPositions(new DH.SQL.OrderPosition {
						Id = Guid.NewGuid(),
						Count = randomizer.Next(0, 100),
						Product = products[randomizer.Next(0, products.Count - 1)] as DH.SQL.Product
					});
				}
				orders.Add(order);
			}
			var toReturn = new Dictionary<Type, IList>();
			toReturn.Add(typeof(IOrder), orders);
			toReturn.Add(typeof(IProduct), products);
			return toReturn;
		}

		internal static Dictionary<Type, IList> CreateWPFOrdersWithContentSmall() {
			var p = new WPFProduct("Prod", 10);
			IOrder o1 = new WPFOrder { Name = "Order1" };
			o1.OrderPositions.Add(new WPFOrderPosition(1, p));

			IOrder o2 = new WPFOrder { Name = "Order2" };
			o2.OrderPositions.Add(new WPFOrderPosition(2, p));

			var toReturn = new Dictionary<Type, IList>();
			toReturn.Add(typeof(IOrder), new List<IOrder>(new[] { o1, o2 }));
			toReturn.Add(typeof(IProduct), new List<IProduct>(new IProduct[] { p }));
			return toReturn;
		}

		#endregion
	}
}